const Ajv = require('ajv').default
const local = require('ajv-i18n')
const ajvError = require('ajv-errors')

const schema = {
    type: 'object',
    properties: {
        name: {
            type: 'string',
            minLength: 12,
            errorMessage: '至少12个字符',
        },
        age: {
            type: 'number',
            maximum: 12,
            minimum: 5,
            errorMessage: {
                type: '必须是数字格式',
                maximum: '至少5岁',
            },
        },
    },
    required: ['age'],
}

const ajv = new Ajv({ allErrors: true, jsonPointers: true })
ajvError(ajv)

const validate = ajv.compile(schema)
const valid = validate({
    name: '12',
    age: 3,
})

local.zh(validate.errors)
console.log(valid)
console.log(validate.errors)
